package com.yiren.dbaa.module.practice_set.basestation;

import android.content.Intent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.yiren.backstage.currency.constant.SignalGConstant;
import com.yiren.dbaa.R;
import com.yiren.dbaa.currency.fragment.LazyLoadFragment;
import com.yiren.dbaa.module.practice_set.basestation.bean.BaseStationBean;
import com.yiren.dbaa.module.practice_set.basestation.contract.BaseStationHomeContract;
import com.yiren.dbaa.module.practice_set.basestation.presenter.BaseStationHomePresenter;
import com.yiren.dbaa.module.practice_set.basestation.view.activity.BaseStationDetailActivity;
import com.yiren.dbaa.module.practice_set.basestation.view.activity.BaseStationManageActivity;
import com.yiren.dbaa.module.practice_set.basestation.view.activity.LocationVerifyActivity;
import com.yiren.dbaa.module.practice_set.basestation.view.adapter.BaseStationHomeAdapter;
import com.yiren.dbaa.view.toast.MessageBox;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author lwb
 * @date : 2022/12/12 9:20
 * @description: 基站首页
 */
public class BaseStationHomeFragment extends LazyLoadFragment implements BaseStationHomeContract.View, BaseStationHomeAdapter.OnManageClickListener {

    @BindView(R.id.lv_basestation)
    ListView lvBaseStation;
    @BindView(R.id.ll_no_data)
    LinearLayout llNoData;
    @BindView(R.id.tv_tips)
    TextView tvTips;

    private BaseStationHomeContract.Presenter baseHomePresenter;

    @Override
    protected int setContentView() {
        return R.layout.fragment_basestation_home;
    }

    @Override
    protected void init() {
        baseHomePresenter = new BaseStationHomePresenter(getActivity());
        tvTips.setText("您当前基站列表为空，请先新增基站！");
        baseHomePresenter.loadBaseStationList(this);
    }

    @Override
    public void onResume() {
        super.onResume();
        baseHomePresenter.loadBaseStationList(this);
    }

    @OnClick({R.id.ll_add_basestation})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ll_add_basestation:  //新增基站
                if (SignalGConstant.isOpen) {
                    startActivity(new Intent(getActivity(), LocationVerifyActivity.class));
                } else {
                    MessageBox.show(getActivity(), "请先去设备设置里面连接基站蓝牙");
                }
                break;
        }
    }

    @Override
    public void showBaseStationList(List<BaseStationBean> baseStationBeanList) {
        if (baseStationBeanList.size() == 0) {
            llNoData.setVisibility(View.VISIBLE);
            lvBaseStation.setVisibility(View.GONE);
        } else {
            llNoData.setVisibility(View.GONE);
            lvBaseStation.setVisibility(View.VISIBLE);
            BaseStationHomeAdapter baseStationHomeAdapter = new BaseStationHomeAdapter(getActivity(), baseStationBeanList, this);
            lvBaseStation.setAdapter(baseStationHomeAdapter);
        }
    }

    @Override
    public void onManageClick(BaseStationBean baseStationBean) {
        Intent intent = new Intent(getActivity(), BaseStationManageActivity.class);
        intent.putExtra("baseStation", baseStationBean);
        startActivity(intent);
    }

    @Override
    public void onDetailsClick(BaseStationBean baseStationBean) {
        Intent intent = new Intent(getActivity(), BaseStationDetailActivity.class);
        intent.putExtra("baseStation", baseStationBean);
        startActivity(intent);
    }
}